<template>
  <div class="dashboard-container">
    <div class="app-container">
      <PageTools>
        <span>本月: 发送双份奖金</span>
        <template #right>
          <el-button type="warning" size="small">excel导入</el-button>
          <el-button type="danger" size="small">excel导出</el-button>
          <el-button type="primary" size="small">新增员工</el-button>
        </template>
      </PageTools>
      <!-- 员工列表 -->
      <el-card style="margin-top: 10px;">
        <el-table :data="list" border>
          <el-table-column label="序号" type="index" sortable="" />
          <el-table-column label="姓名" prop="username" sortable="" />
          <el-table-column label="工号" prop="workNumber" sortable="" />
          <!-- formatter的作用专门用于格式化列的数据 -->
          <el-table-column label="聘用形式" prop="formOfEmployment" :formatter="formatType" sortable="" />
          <!-- <el-table-column label="聘用形式" sortable=""> -->
          <!-- <template v-slot="{row}"> -->
          <!-- {{ row.formOfEmployment===1? hireType[0].value: hireType[1].value }} -->
          <!-- {{ formHiretype(row.formOfEmployment) }} -->
          <!-- {{ row.formOfEmployment | formatType }} -->
          <!-- </template> -->
          <!-- </el-table-column> -->
          <el-table-column label="部门" prop="departmentName" sortable="" />
          <el-table-column label="入职时间" prop="timeOfEntry" sortable="" />
          <el-table-column label="账户状态" prop="enableState" sortable="" />
          <el-table-column label="操作" sortable="" fixed="right" width="280">
            <template>
              <el-button type="text" size="small">查看</el-button>
              <el-button type="text" size="small">转正</el-button>
              <el-button type="text" size="small">调岗</el-button>
              <el-button type="text" size="small">离职</el-button>
              <el-button type="text" size="small">角色</el-button>
              <el-button type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <div style="height: 60px; margin-top: 10px">
          <el-pagination :current-page="queryParams.page" :page-size="queryParams.size" :total="total" layout="prev, pager, next" @current-change="changePage" />
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { reqGetEmployeeList } from '@/api/employees.js'
import Types from '@/api/constant/employees.js'

export default {
  name: 'Employees',
  // 局部过滤器
  // filters: {
  //   formatType (value) {}
  // }
  data () {
    return {
      // 聘用形式
      hireType: Types.hireType,
      // 列表总数
      total: 0,
      // 员工列表
      list: [],
      // 查询参数
      queryParams: {
        page: 1,
        size: 10
      }
    }
  },
  created () {
    this.loadEmpList()
  },
  methods: {
    // 格式化聘用形式：参数一表示row
    formatType (row) {
      const info = this.hireType.find(item => parseInt(item.id) === parseInt(row.formOfEmployment))
      if (info) {
        return info.value
      } else {
        return '其他'
      }
    },
    // 监听页码的变化
    changePage (page) {
      this.queryParams.page = page
      this.loadEmpList()
    },
    // 加载员工列表数据
    async loadEmpList () {
      const ret = await reqGetEmployeeList(this.queryParams)
      if (ret.code === 10000) {
        this.list = ret.data.rows
        this.total = ret.data.total
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
